<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>表单</title>
    <link rel="stylesheet" href="__STATIC__/frame/layui/css/layui.css">
    <link rel="stylesheet" href="__STATIC__/frame/static/css/style.css">
    <link rel="icon" href="__STATIC__/frame/static/image/code.png">
</head>
<body class="body">
<form action="">
    <div class="layui-form-item">
        <label class="layui-form-label">一级分类</label>
        <div class="layui-input-block">
           <select id="class_id" class="layui-select">
               <option value="">选择一级分类</option>
               {foreach $class as $value}
               <option value="{$value['id']}">{$value['class_name']}</option>
               {/foreach}
           </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">二级分类</label>
        <div class="layui-input-block">
            <select class="layui-select" name="branch_id">
                <option value="">选择二级分类</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">三级分类</label>
        <div class="layui-input-block">
            <select class="layui-select" name="three_level_id">
                <option value="">选择三级分类</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">设置提现点数</label>
        <div class="layui-input-block">
            <input class="layui-input" type="text" name="spot">
        </div>
    </div>
</form>
<div style="text-align: center">
    <button class="layui-btn" id="tijiao">提交</button>
</div>
<script src="__STATIC__/frame/layui/layui.all.js" charset="utf-8"></script>
<script src="__STATIC__/js/jquery.3.3.1.min.js" charset="utf-8"></script>
<script src="__STATIC__/js/maowenke.js" charset="utf-8"></script>
<script>
$("#tijiao").click(function () {
    var $id = $("[name=three_level_id]").val();
    var $spot = $("[name=spot]").val();
    if(!$spot||$spot==' '){
        $spot = 0;
    }
    $.post("{:url('update/tixiandian')}",{id:$id,spot:$spot},function (data) {
        if(data.code==200){
           layer.msg(data.msg);
           setTimeout(function () {
               var index = parent.layer.getFrameIndex(window.name);
               parent.layer.close(index);
           },1500);
        }else{
            layer.msg(data.msg);
        }
    })
});
$("[name=three_level_id]").change(function () {
    var $id = $(this).val();
    $.post("{:url('api/three_level_info')}",{id:$id},function (data) {
        console.log(data);
        $("[name=spot]")  .val('');
        if(data.code==200){
          $("[name=spot]").val(data.data.spot);
        }else{
            layer.msg(data.msg);
        }
    })
});
$("[name=branch_id]").change(function () {
    var $id = $(this).val();
    console.log($id);
    getthree_level_id($id);
});
    $("#class_id").change(function () {
        var $class_id = $(this).val();
        if(!$class_id){
            layer.msg('请输入要查看的一级分类名称');
            return;
        }
        $.post("{:url('api/get_Branch')}",{id:$class_id},function (data) {
            if(data.code==200){
                $("[name=branch_id]").empty();
                var $str = '';
                $.each(data.data,function (i,v) {
                    $str +='<option value="'+v.id+'">'+v.branch_name+'</option>'
                });
                $("[name=branch_id]").append($str);
                var $sid = $("[name=branch_id]").val();
                getthree_level_id($sid);
            }else{
                layer.msg(data.msg);
            }
        })
    });
    function getthree_level_id($id) {
        $.post("{:url('api/getBank')}",{id:$id},function (data) {
            if(data.code==200){
              $("[name=three_level_id]").empty();
              var $str = '';
                $("[name=spot]").val('');
              $.each(data.data,function (i,v) {
                  if(i==0){
                      $("[name=spot]").val(v.spot);
                      $str += '<option value="'+v.id+'">'+v.three_level_name+'</option>';
                  }else{
                      $str += '<option value="'+v.id+'">'+v.three_level_name+'</option>';
                  }

              });
                $("[name=three_level_id]").append($str);
            }else{
                layer.msg(data.msg);
            }
        })
    }
</script>
</body>
</html>